package server.controller;

import java.util.ArrayList;
import java.util.Iterator;

import server.util.Logger;

/**
 * The Class ActiveSessions
 * - used to store ClientSessions.
 */
public class ActiveSessions {
	
	/** The session list. */
	private ArrayList<ClientSession> sessionList = new ArrayList<ClientSession>();
	
	/** The logger to use for error reporting. */
	private Logger logger;

	/**
	 * Instantiates a new ActiveSessions.
	 *
	 * @param logger the logger
	 */
	public ActiveSessions(Logger logger) {
		this.logger = logger;
	}

	/**
	 * Adds the session to the sessionlist.
	 *
	 * @param cli the clientsession to be added
	 */
	public synchronized void addSession(ClientSession cli) {
		sessionList.add(cli);
		logger.log("New client connected: " + cli);
	}

	/**
	 * Iterator - gets the clientsession list iterator.
	 *
	 * @return the iterator
	 */
	public synchronized Iterator<ClientSession> iterator() {
		return sessionList.iterator();
	}
	
	/**
	 * Removes a clientsession from the clientsession list.
	 *
	 * @param cli the client to be removed from the list
	 */
	public synchronized void removeFromList(ClientSession cli){
		sessionList.remove(cli);
	}
}